package com.sys.service;

import com.basemodel.Result;
import com.common.ServiceSupport;
import com.exception.ApiException;
import com.sys.mapper.SysUserMapper;
import com.sys.model.SysUser;
import com.sys.service.dto.SysUserDTO;
import com.util.CopyBeanUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: cxt
 * @time: 2022/7/21
 */
@Service
public class SysUserService extends ServiceSupport<SysUser, SysUserMapper> {
    /**
     * 更新
     *
     * @param dto 更新参数
     */
    public void updateSysUser(SysUserDTO dto) {
        SysUser sysUser = CopyBeanUtil.copyBean(dto, SysUser.class);
        sysUser.setUpdateBy("admin");
        sysUser.setUpdateTime(new Date());
        if (!updateSelection(sysUser)) {
            throw new ApiException(Result.UPDATE_FA);
        }
    }

    /**
     * 保存成功
     *
     * @param dto 保存参数
     */
    public void saveSysUser(SysUserDTO dto) {
        SysUser sysUser = CopyBeanUtil.copyBean(dto, SysUser.class);
        sysUser.setCreateBy("admin");
        sysUser.setCreateTime(new Date());
        if (!save(sysUser)) {
            throw new ApiException(Result.SAVE_FA);
        }
    }
}
